<?php
class Useradmin_Model_Useradmin {
	
	private $userList;
	private $addForm;
	private $editForm;
	private $removeAction;
	private $addAction;
	private $editAction;
	
	public function __construct(){
		$this->userList = new Useradmin_Data_Userlist;
		$this->addForm = new Useradmin_Data_Addform;
		$this->editForm = new Useradmin_Data_Editform;
		$this->removeAction = new Useradmin_Data_Removeaction;
		$this->addAction = new Useradmin_Data_Addaction;
		$this->editAction = new Useradmin_Data_Editaction;
	}
	
	public function manageActions(array $getVars, array $postVars){
		if(isset($getVars['page'])){
			$page = $getVars['page'];
			$article['template'] = SERVER_ROOT."useradmin/views/action.php";
			switch($page){
				case "add":
					$article['form'] = $this->addForm->getForm();
					break;
				case "edit":
					$article['form'] = $this->editForm->getForm($getVars);
					break;
				case "remove":
					$this->removeAction->removeUser($getVars);
					break;
				case "added":
					$this->addAction->addUser($postVars);
					break;
				case "updated":
					$this->editAction->editUser($postVars);
					break;
				default:
					echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?useradmin">';
			}
			return $article;
		}
		else {
			$article['form'] = $this->userList->getUserList();
			$article['template'] = SERVER_ROOT."useradmin/views/userlist.php";
			return $article;
		}
	}
	
}